package com.example.administrator.activity.parcitise.Storage.QQ;

import android.content.Context;
import android.os.Environment;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.HashMap;

public class OutQQActivity  {




    public static HashMap<String, String> get(Context context) {
        HashMap<String,String> hashMap=new HashMap<String, String>();
       String device=Environment.getExternalStorageState();
       if (device.equals(Environment.MEDIA_MOUNTED)){
           File sdPath=Environment.getExternalStorageDirectory();
           File file=new File(sdPath,"qq1.txt");
           FileInputStream inputStream;
           BufferedReader reader;
           try {
               inputStream=new FileInputStream(file);
               reader=new BufferedReader(new InputStreamReader(inputStream));
            String line;
            while ((line=reader.readLine())!=null){
                String[] s=line.split(":");
                hashMap.put("name",s[0]);
                hashMap.put("pwd",s[1]);
            }

           } catch (Exception e) {
               e.printStackTrace();
           }
       }return hashMap;
    }

    public static boolean save(Context context, String name, String pwd) {
        String device=Environment.getExternalStorageState();
        if (device.equals(Environment.MEDIA_MOUNTED)){
            File sdPAth=Environment.getExternalStorageDirectory();
            File file=new File(sdPAth,"qq1.txt");
            FileOutputStream outputStream;
            BufferedWriter writer;
            try {
                outputStream=new FileOutputStream(file);
                writer=new BufferedWriter(new OutputStreamWriter(outputStream));
                writer.write(name+":"+pwd);
                writer.flush();
                return true;
            } catch (Exception e) {
                e.printStackTrace();
                return false;
            }
        }
        return false;
    }
}
